<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>欢迎来到guo的博客!</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta property="og:type" content="website">
<meta property="og:title" content="欢迎来到guo的博客!">
<meta property="og:url" content="http://shangguan-lingfeng.gitee.io/blog1/page/2/index.html">
<meta property="og:site_name" content="欢迎来到guo的博客!">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="Jerry">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/blog1/atom.xml" title="欢迎来到guo的博客!" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/blog1/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/blog1/css/style.css">

  
    
<link rel="stylesheet" href="/blog1/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 5.3.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/blog1/" id="logo">欢迎来到guo的博客!</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/blog1/">Home</a>
        
          <a class="main-nav-link" href="/blog1/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/blog1/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Suche"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Suche"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://shangguan-lingfeng.gitee.io/blog1"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main">
  
    <article id="post-nginx部署vue项目" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/04/20/nginx%E9%83%A8%E7%BD%B2vue%E9%A1%B9%E7%9B%AE/" class="article-date">
  <time class="dt-published" datetime="2021-04-19T16:00:00.000Z" itemprop="datePublished">2021-04-20</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/04/20/nginx%E9%83%A8%E7%BD%B2vue%E9%A1%B9%E7%9B%AE/">nginx部署vue项目</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h3 id="1、配置vue目录"><a href="#1、配置vue目录" class="headerlink" title="1、配置vue目录"></a>1、配置vue目录</h3><p>在vue项目config/index.js文件中 找到</p>
<p>build部分的assetsPublicPath  修改值为”./“</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">build: &#123;</span><br><span class="line">        &#x2F;&#x2F; Template for index.html</span><br><span class="line">        index: path.resolve(__dirname, &#39;..&#x2F;dist&#x2F;index.html&#39;),</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; Paths</span><br><span class="line">        assetsRoot: path.resolve(__dirname, &#39;..&#x2F;dist&#39;),</span><br><span class="line">        assetsSubDirectory: &#39;static&#39;,</span><br><span class="line">        assetsPublicPath: &#39;.&#x2F;&#39;, &#x2F;&#x2F;改这里</span><br><span class="line"></span><br><span class="line">        &#x2F;**</span><br><span class="line">         * Source Maps</span><br><span class="line">         *&#x2F;</span><br></pre></td></tr></table></figure>
<p>vue项目开发完以后，部署之前需要 先打包</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm run build</span><br></pre></td></tr></table></figure>
<p>会在vue根目录下生成一个 dist目录</p>
<p>这个就是要部署的部分 </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">- dist</span><br><span class="line">-- static</span><br><span class="line">-- index.html</span><br></pre></td></tr></table></figure>
<h3 id="2、部署conf文件"><a href="#2、部署conf文件" class="headerlink" title="2、部署conf文件"></a>2、部署conf文件</h3><p>我们需要可以在/home/目录下新建一个目录,用来存放部署的dist，可以通过filezilla连接获取到dist</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mkdir &#x2F;home&#x2F;vue_nginx</span><br></pre></td></tr></table></figure>

<p>然后cd进入 /usr/local/nginx/conf/下创建一个目录来存放配置的vue.conf</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">mkdir conf</span><br><span class="line"></span><br><span class="line">cd &#x2F;conf</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;进入vue.conf进行以下文件的配置</span><br><span class="line">vi vue.conf</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line">server &#123;</span><br><span class="line">    listen       8080;  # 此处修改为部署的vue端口号</span><br><span class="line">    server_name  localhost;</span><br><span class="line"></span><br><span class="line">    #charset koi8-r;</span><br><span class="line"></span><br><span class="line">    #access_log  logs&#x2F;host.access.log  main;</span><br><span class="line"></span><br><span class="line">    location &#x2F; &#123;</span><br><span class="line">        root   &#x2F;home&#x2F;vue_nginx&#x2F;dist;    #指定文件目录下部署的dist</span><br><span class="line">        index  index.html index.htm;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    #error_page  404              &#x2F;404.html;</span><br><span class="line"></span><br><span class="line">    # redirect server error pages to the static page &#x2F;50x.html</span><br><span class="line">    #</span><br><span class="line">    error_page   500 502 503 504  &#x2F;50x.html;</span><br><span class="line">    location &#x3D; &#x2F;50x.html &#123;</span><br><span class="line">        root   html;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    # proxy the PHP scripts to Apache listening on 127.0.0.1:80</span><br><span class="line">    #</span><br><span class="line">    #location ~ \.php$ &#123;</span><br><span class="line">    #    proxy_pass   http:&#x2F;&#x2F;127.0.0.1;</span><br><span class="line">    #&#125;</span><br><span class="line"></span><br><span class="line">    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000</span><br><span class="line">    #</span><br><span class="line">    #location ~ \.php$ &#123;</span><br><span class="line">    #    root           html;</span><br><span class="line">    #    fastcgi_pass   127.0.0.1:9000;</span><br><span class="line">    #    fastcgi_index  index.php;</span><br><span class="line">    #    fastcgi_param  SCRIPT_FILENAME  &#x2F;scripts$fastcgi_script_name;</span><br><span class="line">    #    include        fastcgi_params;</span><br><span class="line">    #&#125;</span><br><span class="line"></span><br><span class="line">    # deny access to .htaccess files, if Apache&#39;s document root</span><br><span class="line">    # concurs with nginx&#39;s one</span><br><span class="line">    #</span><br><span class="line">    #location ~ &#x2F;\.ht &#123;</span><br><span class="line">    #    deny  all;</span><br><span class="line">    #&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>改完这两处退出,重启nginx服务</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl restart nginx</span><br></pre></td></tr></table></figure>
<hr>
<p><strong>温馨提示：如果你是使用源码进行安装，而不是yum安装，则需要先进行以下systemctl的设置(如果使用yum安装请忽略以下步骤)</strong></p>
<h4 id="centos7中设置nginx的systemctl启动方式"><a href="#centos7中设置nginx的systemctl启动方式" class="headerlink" title="centos7中设置nginx的systemctl启动方式"></a>centos7中设置nginx的systemctl启动方式</h4><h5 id="1-建立服务文件"><a href="#1-建立服务文件" class="headerlink" title="1.建立服务文件"></a>1.建立服务文件</h5><p>（1）文件路径</p>
<p>vim /usr/lib/systemd/system/nginx.service</p>
<p>（2）将以下内容写入文件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">[Unit]</span><br><span class="line"></span><br><span class="line">Description&#x3D;nginx - high performance web server</span><br><span class="line"></span><br><span class="line">After&#x3D;network.target remote-fs.target nss-lookup.target</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line"></span><br><span class="line">[Service]</span><br><span class="line"></span><br><span class="line">Type&#x3D;forking</span><br><span class="line"></span><br><span class="line">ExecStart&#x3D;&#x2F;opt&#x2F;nginx&#x2F;sbin&#x2F;nginx</span><br><span class="line"></span><br><span class="line">ExecReload&#x3D;&#x2F;opt&#x2F;nginx&#x2F;sbin&#x2F;nginx -s reload</span><br><span class="line"></span><br><span class="line">ExecStop&#x3D;&#x2F;opt&#x2F;nginx&#x2F;sbin&#x2F;nginx -s stop</span><br><span class="line"></span><br><span class="line">[Install]</span><br><span class="line"></span><br><span class="line">WantedBy&#x3D;multi-user.target</span><br></pre></td></tr></table></figure>
<h5 id="2-使服务生效"><a href="#2-使服务生效" class="headerlink" title="2.使服务生效"></a>2.使服务生效</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl daemon-reload</span><br></pre></td></tr></table></figure>
<h5 id="3-重启服务"><a href="#3-重启服务" class="headerlink" title="3.重启服务"></a>3.重启服务</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl restart nginx</span><br></pre></td></tr></table></figure>
<h3 id="其它问题"><a href="#其它问题" class="headerlink" title="其它问题"></a>其它问题</h3><p><strong>centos启动Nginx提示nginx: [emerg] still could not bind()</strong></p>
<p>如果遇到以上问题，可能是进程占用原因</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[root@8.131.52.82 ~]# systemctl restart nginx</span><br><span class="line">nginx: [emerg] bind() to 0.0.0.0:8080 failed (98: Address already in use)</span><br><span class="line">nginx: [emerg] bind() to 0.0.0.0:8080 failed (98: Address already in use)</span><br><span class="line">nginx: [emerg] bind() to 0.0.0.0:8080 failed (98: Address already in use)</span><br><span class="line">nginx: [emerg] bind() to 0.0.0.0:8080 failed (98: Address already in use)</span><br><span class="line">nginx: [emerg] bind() to 0.0.0.0:8080 failed (98: Address already in use)</span><br><span class="line">nginx: [emerg] still could not bind()</span><br></pre></td></tr></table></figure>
<p><strong>解决办法：</strong></p>
<p>根据Nginx配置文件查看配置的端口（本文中使用的是80端口），然后根据端口查看端口占用情况</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@xyw-cyck-cms-3 ~]# netstat -ntlp|grep 8080  </span><br><span class="line">tcp        0      0 0.0.0.0:8080              0.0.0.0:*               LISTEN      7043/nginx: worker</span><br></pre></td></tr></table></figure>
<p>使用kill命令杀死占用进程，之后重新启动Nginx</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">kill -9 7043</span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/04/20/nginx%E9%83%A8%E7%BD%B2vue%E9%A1%B9%E7%9B%AE/" data-id="cknublgbq000pv8uhb15k04ot" data-title="nginx部署vue项目" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/CentOS/" rel="tag">CentOS</a></li></ul>

    </footer>
  </div>
  
</article>



  
    <article id="post-郭家瑞背诵内容day6" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/04/15/%E9%83%AD%E5%AE%B6%E7%91%9E%E8%83%8C%E8%AF%B5%E5%86%85%E5%AE%B9day6/" class="article-date">
  <time class="dt-published" datetime="2021-04-15T01:37:38.460Z" itemprop="datePublished">2021-04-15</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/04/15/%E9%83%AD%E5%AE%B6%E7%91%9E%E8%83%8C%E8%AF%B5%E5%86%85%E5%AE%B9day6/">函数进阶</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h2 id="6-函数进阶"><a href="#6-函数进阶" class="headerlink" title="6.函数进阶"></a>6.函数进阶</h2><h4 id="1-您知道什么是闭包吗？"><a href="#1-您知道什么是闭包吗？" class="headerlink" title="1.您知道什么是闭包吗？"></a>1.您知道什么是闭包吗？</h4><p>​    闭包就是内外层函数的嵌套，内部函数引用外部函数的局部变量，外部函数返回内部函数。</p>
<p>​    <strong>优点：使变量延续下去</strong></p>
<p>​    <strong>缺点：比较浪费内存空间</strong></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">outer</span>():</span></span><br><span class="line">    b = <span class="number">2</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">inner</span>():</span></span><br><span class="line">        print(b)</span><br><span class="line">    <span class="keyword">return</span> inner</span><br><span class="line">func = outer()</span><br><span class="line">print(func)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 该outer函数内部封装了一个inner闭包函数</span></span><br></pre></td></tr></table></figure>
<h4 id="2-您知道什么是装饰器吗？"><a href="#2-您知道什么是装饰器吗？" class="headerlink" title="2.您知道什么是装饰器吗？"></a>2.您知道什么是装饰器吗？</h4><p>​    装饰器利用了闭包的原理，主要是用来对一个函数在不改变原有的功能的情况下额外增加新的功能。函数的返回值也是一个函数。</p>
<p>​    装饰器有三种类型：普通装饰器、被装饰函数带参数、装饰器带参数</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 通常装饰器多用于对请求token进行解析</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">make_token</span>(<span class="params">func</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">inner</span>(<span class="params">request, *args,**kwargs</span>):</span></span><br><span class="line">        token = request.META.get(<span class="string">&#x27;HTTP_AUTHORIZATION&#x27;</span>)</span><br><span class="line">        uid = jwt.decode(token, SECRET_KEY, algorithms=<span class="string">&#x27;HS256&#x27;</span>)[<span class="string">&#x27;uid&#x27;</span>]</span><br><span class="line">        <span class="comment"># 根据请求方式不同对token进行不同的解析</span></span><br><span class="line">        <span class="keyword">if</span> request.method == <span class="string">&quot;POST&quot;</span>:</span><br><span class="line">            request.data[<span class="string">&#x27;user&#x27;</span>] = uid</span><br><span class="line">        request.uid = uid</span><br><span class="line">        <span class="keyword">return</span> func(request, *args,**kwargs)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> inner</span><br></pre></td></tr></table></figure>
<h4 id="3-说说您对递归的理解？"><a href="#3-说说您对递归的理解？" class="headerlink" title="3.说说您对递归的理解？"></a>3.说说您对递归的理解？</h4><p>​    调用函数的时候，直接或间接调用函数的本身这个过程就叫做递归。但是为了避免递归进入死循环，使用递归必须有一个递归条件出口。</p>
<h4 id="4-递归实现斐波那契数列"><a href="#4-递归实现斐波那契数列" class="headerlink" title="4.递归实现斐波那契数列"></a>4.递归实现斐波那契数列</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">n</span>):</span></span><br><span class="line">    <span class="keyword">if</span> n == <span class="number">1</span> <span class="keyword">or</span> n == <span class="number">2</span>:</span><br><span class="line">        <span class="keyword">return</span> <span class="number">1</span></span><br><span class="line">    <span class="keyword">return</span> func(n-<span class="number">1</span>)+func(n-<span class="number">2</span>)</span><br></pre></td></tr></table></figure>
<h4 id="5-您知道函数参数的传值传引用吗？"><a href="#5-您知道函数参数的传值传引用吗？" class="headerlink" title="5.您知道函数参数的传值传引用吗？"></a>5.您知道函数参数的传值传引用吗？</h4><p><strong>python中函数传参都是传引用</strong></p>
<p>传递不可变数据类型的值在函数内部无法直接修改，类似于C</p>
<p>传递可变数据类型的值在函数内部可以直接修改，并且原始数据也会改变。传引用是将内存地址作为参数传递，形参和实参是同一个引用对象，因此形参修改后实参也会发生改变</p>
<p><strong>传递不可变数据为传值，传递可变数据为传引用</strong></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/04/15/%E9%83%AD%E5%AE%B6%E7%91%9E%E8%83%8C%E8%AF%B5%E5%86%85%E5%AE%B9day6/" data-id="cknublgcl0028v8uh48efhdjr" data-title="函数进阶" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/python%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/" rel="tag">python基础知识</a></li></ul>

    </footer>
  </div>
  
</article>



  
    <article id="post-郭家瑞背诵内容day4" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/04/13/%E9%83%AD%E5%AE%B6%E7%91%9E%E8%83%8C%E8%AF%B5%E5%86%85%E5%AE%B9day4/" class="article-date">
  <time class="dt-published" datetime="2021-04-13T13:34:20.688Z" itemprop="datePublished">2021-04-13</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/04/13/%E9%83%AD%E5%AE%B6%E7%91%9E%E8%83%8C%E8%AF%B5%E5%86%85%E5%AE%B9day4/">内存管理</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h2 id="4-内存管理"><a href="#4-内存管理" class="headerlink" title="4.内存管理"></a>4.内存管理</h2><h4 id="1-你懂引用计数吗，可以谈谈吗？"><a href="#1-你懂引用计数吗，可以谈谈吗？" class="headerlink" title="1.你懂引用计数吗，可以谈谈吗？"></a>1.你懂引用计数吗，可以谈谈吗？</h4><p>​    引用计数是编程语言的一种内存管理机制，可以保存资源被引用的次数。当一个对象被引用时计数会加1。当对象被del语句删除一次时，计数会减1。当引用计数为0时，内存会被释放掉。</p>
<p>​    引用计数也会产生一个问题，当两个对象相互进行引用时，这时计数都互不为0，会造成循环引用无法通过常规手段进行回收。python还提供了一个标记-清除的机制来解决这个问题。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> sys</span><br><span class="line">sys.getrefcount(obj)	<span class="comment"># obj代表要进行查询引用计数的对象</span></span><br></pre></td></tr></table></figure>
<h4 id="2-您能说一下标记-清除吗？"><a href="#2-您能说一下标记-清除吗？" class="headerlink" title="2.您能说一下标记-清除吗？"></a>2.您能说一下标记-清除吗？</h4><p>​    标记-清除共分为两个阶段：垃圾检测阶段(Mark)和垃圾回收(Sweep)阶段。</p>
<p>​    垃圾检测阶段主要是由根对象依次往下进行访问，将所有的指针指向关系构成一个有向图，可以访问的我们暂且称为可到达对象，不可以访问的称为不可到达对象。我们会对可到达对象进行标记。</p>
<p>​    垃圾回收阶段我们会从头到尾进行遍历，把标记的可到达对象保留，其余未标记的对象进行回收清除，完成之后会将标记全部消除，以便于下次的标记-清除操作。</p>
<p>​    但是标记-清除也会产生两个问题：每次进行完标记-清除都会产生很多内存碎片。还有由于进行标记的对象过多时，每次进行清除的时候都会把大量的时间浪费在遍历上。</p>
<p>​    <strong>标记-清除的一些名词</strong>：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># collector  垃圾回收器</span></span><br><span class="line"><span class="comment"># mutator	不属于垃圾回收器的部分，主要用来创建新对象和读写内存</span></span><br><span class="line"><span class="comment"># mutator roots	根对象(全局对象、调用栈、寄存器)</span></span><br><span class="line"><span class="comment"># 可到达对象 被遍历可以访问的标记对象</span></span><br></pre></td></tr></table></figure>
<h4 id="3-分代回收又是什么呢？"><a href="#3-分代回收又是什么呢？" class="headerlink" title="3.分代回收又是什么呢？"></a>3.分代回收又是什么呢？</h4><p>​    分代回收是基于标记-清除上诞生的，主要用于处理标记-清除所遗留的内存遍历时间长的问题。是以空间换时间的一种回收机制。对象存在时间越久就越不去回收</p>
<p>​    分代回收大体就是把回收对象分成青年代、中年代、老年代。每代都有一个单链表进行存储，当青年代的单链表满时，会触发标记-清除，把青年代标记的对象转移到中年代，其它的对象进行清除操作，中年代到老年代依次进行这样的操作。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 分代回收的触发机制</span></span><br><span class="line"><span class="keyword">import</span> gc</span><br><span class="line">print(gc.get_threshold())</span><br></pre></td></tr></table></figure>
<pre><code>python的分代回收的机制默认当分配对象个数减去释放对象个数的差值大于 700 时 就会产生一次 0 代回收
10 次 0 代回收会导致一次 1 代回收
10 次 1 代回收会导致 一次 2 代回收</code></pre>
<p>​    老年代的存活时间非常久，几乎存活于整个系统的生命周期</p>
<p>​    </p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/04/13/%E9%83%AD%E5%AE%B6%E7%91%9E%E8%83%8C%E8%AF%B5%E5%86%85%E5%AE%B9day4/" data-id="cknublgck0026v8uh70wdhfhh" data-title="内存管理" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/python%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/" rel="tag">python基础知识</a></li></ul>

    </footer>
  </div>
  
</article>



  
    <article id="post-郭家瑞背诵内容day3" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/04/13/%E9%83%AD%E5%AE%B6%E7%91%9E%E8%83%8C%E8%AF%B5%E5%86%85%E5%AE%B9day3/" class="article-date">
  <time class="dt-published" datetime="2021-04-13T13:34:20.686Z" itemprop="datePublished">2021-04-13</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/04/13/%E9%83%AD%E5%AE%B6%E7%91%9E%E8%83%8C%E8%AF%B5%E5%86%85%E5%AE%B9day3/">数据类型</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h2 id="3-数据类型"><a href="#3-数据类型" class="headerlink" title="3.数据类型"></a>3.数据类型</h2><h4 id="1-python可变数据类型和不可变数据类型"><a href="#1-python可变数据类型和不可变数据类型" class="headerlink" title="1.python可变数据类型和不可变数据类型"></a>1.python可变数据类型和不可变数据类型</h4><p>​    可变数据类型：列表，字典，集合，</p>
<p>​    不可变数据类型：数字，字符串，元祖</p>
<h4 id="2-列表和元组的区别"><a href="#2-列表和元组的区别" class="headerlink" title="2.列表和元组的区别"></a>2.列表和元组的区别</h4><p>​    列表的数据是可变的，元组的数据是不可变的。两者的提供方法、使用场景、性能都有很大差别。在处理大数据量的时候，元组由于数据无法改变，所以就导致元组的可操作性会更强。</p>
<p>列表一般用于存储同构数据(具有相同意义的数据)，元组一般用于存储异构数据(具有不同意义的数据)</p>
<h4 id="3-说说字典的底层"><a href="#3-说说字典的底层" class="headerlink" title="3.说说字典的底层"></a>3.说说字典的底层</h4><p>​    字典是python的数据结构之一，可以将一组唯一的键找到响应的值。</p>
<p>​    CPython使用伪随机探测(计算机随机算法的随机数)的散列表(hash数组)作为字典的底层数据结构</p>
<p>​    python中所有不可变的数据类型都是可hash的，可变类型都是不可hash的。</p>
<p>​    字典的添加、获取、删除的平均事件复杂度为O(1)，但是平台最坏复杂度为O(N)</p>
<p>​    <strong>开放寻址法</strong>:因为在python3.6之前字典为无序的，可以使用开放寻址法实现hash数组。</p>
<p>​        所有的数据都存放在hash数组里，当存放产生哈希冲突时，这时会通过一个hash的一个算法计算出下一个空槽，如果下一个位置依旧哈希冲突，那么继续运算直到找到空槽进行存储该数据。</p>
<p>​    hash数组优缺点：继承了数组的优点，对CPU缓冲好，容易序列化，但内存利用率不高，且很容易造成哈希冲突。</p>
<p>​    当数据量较小时，推荐使用开放寻址法</p>
<p>​    <strong>拉链法</strong>:在python3.6版本之后字典变为有序的，底层可以使用拉链法实现。</p>
<p>​        将所有同义词关键字存放在一个单链表中，hash表中只存储单链表的头指针，遇到哈希冲突直接追加到单链表末尾，一定程度解决了哈希冲突过多的问题。</p>
<p>​        但是极特殊情况下可能在同一个链表发生大量的哈希冲突，这时查找的速度可能会变慢</p>
<p>​        红黑树：当链表过长，会升级为红黑树来加快查询速度</p>
<p>​            1.根节点是黑色节点，叶子节点是不存储数据的黑色空节点</p>
<p>​            2.任何相邻的两个节点不能同时为红色</p>
<p>​            3.任意节点到其可达到的叶子节点间包含相同数量的黑色节点</p>
<h4 id="4-字符串内置方法"><a href="#4-字符串内置方法" class="headerlink" title="4.字符串内置方法"></a>4.字符串内置方法</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># str.replace:替换字符串的指定字符为新字符</span></span><br><span class="line"><span class="string">&#x27;1*2*3*&#x27;</span>.replace(<span class="string">&#x27;*&#x27;</span>,<span class="string">&#x27;#&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 结果：1#2#3#</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># str.startswith:查找开头指定字符的字符串</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># str.split</span></span><br><span class="line"><span class="comment"># 以指定字符为分隔符，分割字符串为列表</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># str.join</span></span><br><span class="line"><span class="comment"># 以指定字符为拼接符，拼接成字符串</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># str.endswith:查找结尾指定字符的字符串</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># str.strip:删除字符串首尾空白字符</span></span><br></pre></td></tr></table></figure>


<h4 id="5-列表内置方法"><a href="#5-列表内置方法" class="headerlink" title="5.列表内置方法"></a>5.列表内置方法</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># list.append:用于在列表末尾添加新的对象</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># list.count:用于统计某个元素在列表中出现的次数</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># list.extend:拼接列表数据</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># list.index:查找列表某个值的第一次出现的下标</span></span><br><span class="line">功能、性能、优化、部署</span><br><span class="line"><span class="comment"># list.insert:在列表指定位置插入指定的值</span></span><br></pre></td></tr></table></figure>
<h4 id="6-集合内置方法"><a href="#6-集合内置方法" class="headerlink" title="6.集合内置方法"></a>6.集合内置方法</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">set</span>.difference:求两个集合的差集</span><br><span class="line">    </span><br><span class="line"><span class="built_in">set</span>.intersection:求两个集合的交集(第一个集合里有第二个集合的)</span><br><span class="line">    </span><br><span class="line"><span class="built_in">set</span>.union:求两个集合的并集(两个集合共有的)</span><br><span class="line">    </span><br><span class="line"><span class="built_in">set</span>.add:给集合添加数据</span><br><span class="line">    </span><br><span class="line"><span class="built_in">set</span>.remote:删除集合指定数据</span><br><span class="line">    </span><br><span class="line"><span class="built_in">set</span>.clear:清空集合</span><br></pre></td></tr></table></figure>
<h4 id="7-字典内置方法"><a href="#7-字典内置方法" class="headerlink" title="7.字典内置方法"></a>7.字典内置方法</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">dict</span>.keys:结果返回一个dict_keys对象，可以查看字典的所有键</span><br><span class="line">    </span><br><span class="line"><span class="built_in">dict</span>.values:结果返回一个dict_values对象，可以查看字典的所有值</span><br><span class="line">    </span><br><span class="line"><span class="built_in">dict</span>.items:结果返回一个dict_items对象，可以查看字典的键值对</span><br><span class="line">    </span><br><span class="line"><span class="built_in">dict</span>.clear清空字典</span><br><span class="line"></span><br><span class="line"><span class="built_in">dict</span>.copy浅拷贝字典</span><br><span class="line"></span><br><span class="line"><span class="built_in">dict</span>.update合并两个字典</span><br></pre></td></tr></table></figure>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/04/13/%E9%83%AD%E5%AE%B6%E7%91%9E%E8%83%8C%E8%AF%B5%E5%86%85%E5%AE%B9day3/" data-id="cknublgcj0024v8uhdorm61j8" data-title="数据类型" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/python%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/" rel="tag">python基础知识</a></li></ul>

    </footer>
  </div>
  
</article>



  
    <article id="post-郭家瑞背诵内容day2" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/04/13/%E9%83%AD%E5%AE%B6%E7%91%9E%E8%83%8C%E8%AF%B5%E5%86%85%E5%AE%B9day2/" class="article-date">
  <time class="dt-published" datetime="2021-04-13T13:34:20.683Z" itemprop="datePublished">2021-04-13</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/04/13/%E9%83%AD%E5%AE%B6%E7%91%9E%E8%83%8C%E8%AF%B5%E5%86%85%E5%AE%B9day2/">语法基础</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h2 id="2-语法基础"><a href="#2-语法基础" class="headerlink" title="2.语法基础"></a>2.语法基础</h2><h4 id="1-is和-的区别"><a href="#1-is和-的区别" class="headerlink" title="1.is和==的区别"></a>1.is和==的区别</h4><p>​    is主要用来判断两个对象是否完全相同，两个对象的内存地址的指向是否一致。</p>
<p>​    ==主要用来判断两个对象的值是否相同，两个对象的类型是否相同。</p>
<h4 id="2-range和xrange的区别"><a href="#2-range和xrange的区别" class="headerlink" title="2.range和xrange的区别"></a>2.range和xrange的区别</h4><p>​    python2中xrange有，python3中没有</p>
<p>​    range结果返回一个列表，xrange结果返回一个可迭代对象</p>
<p>​    python2中xrange存在，python3中被range代替了,它们的作用相同</p>
<p>​    xrange返回的是可迭代对象，每次调用返回一个值。内存空间占用相比range更少，性能更好</p>
<h4 id="3-三元表达式"><a href="#3-三元表达式" class="headerlink" title="3.三元表达式"></a>3.三元表达式</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">x = <span class="number">1</span></span><br><span class="line">y = <span class="number">2</span></span><br><span class="line">human = <span class="string">&#x27;男&#x27;</span> <span class="keyword">if</span> x &lt; y <span class="keyword">else</span> <span class="string">&#x27;女&#x27;</span></span><br><span class="line">print(x)</span><br><span class="line"><span class="comment"># x = 女</span></span><br></pre></td></tr></table></figure>
<h4 id="4-深拷贝，浅拷贝"><a href="#4-深拷贝，浅拷贝" class="headerlink" title="4.深拷贝，浅拷贝"></a>4.深拷贝，浅拷贝</h4><p>​    深拷贝：copy.deepcopy()</p>
<p>​    深拷贝是拷贝原变量的一整套内容，完全相同，修改拷贝数据原数据不会受到任何影响</p>
<p>​    浅拷贝：copy.copy()</p>
<p>​    浅拷贝是只拷贝原变量的第一层，深层次不会拷贝，看上去相同，但是如果改变拷贝内容，原来除第一层外的其它层也会改变</p>
<h4 id="5-python的自省"><a href="#5-python的自省" class="headerlink" title="5.python的自省"></a>5.python的自省</h4><p>​    python自省：在程序运行中可获取某个对象的属性或类型</p>
<ul>
<li>dir 获取当前对象内部的属性</li>
<li>type 获取当前对象的类型</li>
<li>hasattr 判断对象是否包含某个属性</li>
<li>getattr 获取对象的属性</li>
<li>isinstance 判断对象是否是某个类的实例</li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/04/13/%E9%83%AD%E5%AE%B6%E7%91%9E%E8%83%8C%E8%AF%B5%E5%86%85%E5%AE%B9day2/" data-id="cknublgca001mv8uh1b96cd8m" data-title="语法基础" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/python%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/" rel="tag">python基础知识</a></li></ul>

    </footer>
  </div>
  
</article>



  
    <article id="post-郭家瑞背诵内容day1" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/04/13/%E9%83%AD%E5%AE%B6%E7%91%9E%E8%83%8C%E8%AF%B5%E5%86%85%E5%AE%B9day1/" class="article-date">
  <time class="dt-published" datetime="2021-04-13T13:34:20.680Z" itemprop="datePublished">2021-04-13</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/04/13/%E9%83%AD%E5%AE%B6%E7%91%9E%E8%83%8C%E8%AF%B5%E5%86%85%E5%AE%B9day1/">语言相关</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h3 id="1-语言相关"><a href="#1-语言相关" class="headerlink" title="1.语言相关"></a>1.语言相关</h3><h4 id="1-1-解释型和编译型语言的区别"><a href="#1-1-解释型和编译型语言的区别" class="headerlink" title="1.1 解释型和编译型语言的区别"></a>1.1 解释型和编译型语言的区别</h4><p>​    解释型语言：python，JavaScript，PHP，shell</p>
<p>​    编译型语言：C，C++，Golang</p>
<p>​    解释型语言，需要一个解释器来开辟一个内存空间，占用空间影响效率。源代码一边转换一边执行，调试bug和书写代码比较方便，但是执行比较耗时。</p>
<p>​    编译型语言，需要对源代码进行编译打包成一个程序来执行，所以中途出现bug不方便调试，但是由于语言不需要进行解释，打包后可以直接执行，执行方便。</p>
<h4 id="1-2-python2和python3的区别"><a href="#1-2-python2和python3的区别" class="headerlink" title="1.2 python2和python3的区别"></a>1.2 python2和python3的区别</h4><p>​    python2中print为语句, python3中print为方法</p>
<p>​    python2编码为ASCII码值, python3编码为Unicode</p>
<p>​    python2中除法结果为整数, python3中除法结果为浮点数</p>
<p>​    python2函数map返回为list, python3 函数map返回为迭代器</p>
<p>​    python2中xrange存在，python3中被range代替了</p>
<h4 id="1-3-解释器种类及特点"><a href="#1-3-解释器种类及特点" class="headerlink" title="1.3 解释器种类及特点"></a>1.3 解释器种类及特点</h4><ol>
<li>CPython: 使用最广的解释器, 基于C语言开发的, 具有GIL锁 。</li>
<li>IPython: 和CPython差不多, 是一个交互解释器。</li>
<li>Jython: 运行在Java平台上的Python解释器, 可以把Python代码编译成Java字节码执行。</li>
<li>IronPython: IronPython和Jython类似, 不同的是IronPython 是运行在微软.Net平台上的, 可以把Python代码编译成.Net字节码执行。</li>
<li>PyPy: python另一个解释器，主要用来提高执行效率，其执行效率采用了JIT技术, 对Python代码进行动态编译, 提高执行效率。</li>
</ol>
<h4 id="1-4-PEP8规范"><a href="#1-4-PEP8规范" class="headerlink" title="1.4 PEP8规范"></a>1.4 PEP8规范</h4><ul>
<li><p>RFC(request of comments): 专门用来定义网络请求的标准文档, 是一系列以编号排定的文件, 文件收集了有关互联网相关信息.</p>
</li>
<li><p>PEP8</p>
<p>每次缩进4个空格, 每行最多79个字符, 长导包语句和URL地址除外</p>
<p>不推荐同行导入多个包</p>
<p>避免变量名使用关键字</p>
<p>类采用大驼峰命名法, 变量名和函数名是下划线命名法</p>
<p>类的开头为大写，函数开头为小写</p>
</li>
</ul>
<h4 id="1-5-常见编码有哪些"><a href="#1-5-常见编码有哪些" class="headerlink" title="1.5 常见编码有哪些"></a>1.5 常见编码有哪些</h4><p>​    utf-8    不定长编码，通常为2个字符</p>
<p>​    ASCII    通常为1个字符</p>
<p>​    Unicode    标准字符集，通常为2个字符</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/04/13/%E9%83%AD%E5%AE%B6%E7%91%9E%E8%83%8C%E8%AF%B5%E5%86%85%E5%AE%B9day1/" data-id="cknublgc9001kv8uh8u1z4351" data-title="语言相关" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/python%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/" rel="tag">python基础知识</a></li></ul>

    </footer>
  </div>
  
</article>



  
    <article id="post-郭家瑞背诵内容day5" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/04/13/%E9%83%AD%E5%AE%B6%E7%91%9E%E8%83%8C%E8%AF%B5%E5%86%85%E5%AE%B9day5/" class="article-date">
  <time class="dt-published" datetime="2021-04-13T13:34:20.670Z" itemprop="datePublished">2021-04-13</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/04/13/%E9%83%AD%E5%AE%B6%E7%91%9E%E8%83%8C%E8%AF%B5%E5%86%85%E5%AE%B9day5/">函数基础</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h2 id="6-函数基础"><a href="#6-函数基础" class="headerlink" title="6.函数基础"></a>6.函数基础</h2><h4 id="1-python高阶方法"><a href="#1-python高阶方法" class="headerlink" title="1.python高阶方法"></a>1.python高阶方法</h4><pre><code>##### map函数:依次将function函数作用在可迭代对象的每一个值上，结果返回一个迭代器</code></pre>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">function</span>():</span></span><br><span class="line">    <span class="keyword">return</span> x*x</span><br><span class="line"></span><br><span class="line">func = <span class="built_in">map</span>(function,[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>,<span class="number">7</span>,<span class="number">8</span>,<span class="number">9</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment"># 我们无法直接拿到迭代器的结果，所以需要用tuple或list强转类型拿到结果</span></span><br><span class="line">print(<span class="built_in">list</span>(func))</span><br><span class="line"></span><br><span class="line"><span class="comment"># 返回结果：[1,4,9,16,25,36,49,64,81]</span></span><br></pre></td></tr></table></figure>
<h5 id="filter函数-该函数需要接收函数和序列作为参数使用，将序列每个值都交给定义函数的方法计算，返回结果为True则保留到迭代器中"><a href="#filter函数-该函数需要接收函数和序列作为参数使用，将序列每个值都交给定义函数的方法计算，返回结果为True则保留到迭代器中" class="headerlink" title="filter函数:该函数需要接收函数和序列作为参数使用，将序列每个值都交给定义函数的方法计算，返回结果为True则保留到迭代器中"></a>filter函数:该函数需要接收函数和序列作为参数使用，将序列每个值都交给定义函数的方法计算，返回结果为True则保留到迭代器中</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">function</span>(<span class="params">num</span>):</span></span><br><span class="line">    <span class="keyword">return</span> num % <span class="number">2</span> == <span class="number">0</span>	<span class="comment"># 该函数判断参数是否为偶数</span></span><br><span class="line"></span><br><span class="line">func = <span class="built_in">filter</span>(function,[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment"># 我们无法直接拿到迭代器的结果，所以需要用tuple或list强转类型拿到结果</span></span><br><span class="line">print(<span class="built_in">list</span>(func))</span><br><span class="line"><span class="comment"># 返回结果：[2,4]</span></span><br></pre></td></tr></table></figure>
<h5 id="reduce函数-主要将接收的序列用作累计运算，函数接收序列前两个数第一次运算的结果作为下一次的结果第一个数，依次类推。"><a href="#reduce函数-主要将接收的序列用作累计运算，函数接收序列前两个数第一次运算的结果作为下一次的结果第一个数，依次类推。" class="headerlink" title="reduce函数:主要将接收的序列用作累计运算，函数接收序列前两个数第一次运算的结果作为下一次的结果第一个数，依次类推。"></a>reduce函数:主要将接收的序列用作累计运算，函数接收序列前两个数第一次运算的结果作为下一次的结果第一个数，依次类推。</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">function</span>(<span class="params">num1,num2</span>):</span></span><br><span class="line">    <span class="keyword">return</span> num1+num2</span><br><span class="line"></span><br><span class="line">func = reduce(function,[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment"># 结果返回为一个累计计算的结果</span></span><br><span class="line">print(func)</span><br><span class="line"><span class="comment"># 返回结果15</span></span><br></pre></td></tr></table></figure>
<h5 id="sorted函数-对可迭代对象进行排序"><a href="#sorted函数-对可迭代对象进行排序" class="headerlink" title="sorted函数:对可迭代对象进行排序"></a>sorted函数:对可迭代对象进行排序</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">print(<span class="built_in">sorted</span>([<span class="number">36</span>,<span class="number">5</span>,-<span class="number">12</span>,<span class="number">9</span>,-<span class="number">21</span>]),reverse=<span class="literal">True</span>)	<span class="comment"># reverse对结果进行逆置，默认为Flask升序</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># keys=abs</span></span><br><span class="line"><span class="comment"># 可对绝对值进行排序</span></span><br></pre></td></tr></table></figure>
<h4 id="2-lambda表达式及其跳转表您懂吗？"><a href="#2-lambda表达式及其跳转表您懂吗？" class="headerlink" title="2.lambda表达式及其跳转表您懂吗？"></a>2.lambda表达式及其跳转表您懂吗？</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">lambda</span> 指定参数:指定参数用法</span><br></pre></td></tr></table></figure>
<h4 id="3-不定长参数"><a href="#3-不定长参数" class="headerlink" title="3.不定长参数"></a>3.不定长参数</h4><p>*args接收单个参数，接收后存为元祖</p>
<p>**kwargs接收以键值对形式的参数，接收后存为字典</p>
<h4 id="4-您知道pass吗？"><a href="#4-您知道pass吗？" class="headerlink" title="4.您知道pass吗？"></a>4.您知道pass吗？</h4><p>pass就是空语句，可以当做占位符</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">function</span>():</span>	<span class="comment"># 如果直接写一个空函数，程序会报异常</span></span><br><span class="line">    <span class="keyword">pass</span>		<span class="comment"># 使用pass占位后就可以正常运行</span></span><br></pre></td></tr></table></figure>
<h4 id="5-global和nonlocal的作用"><a href="#5-global和nonlocal的作用" class="headerlink" title="5.global和nonlocal的作用"></a>5.global和nonlocal的作用</h4><p>global:定义全局变量，可以全局使用</p>
<p>nonlocal:局部变量，只能在嵌套函数中使用</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/04/13/%E9%83%AD%E5%AE%B6%E7%91%9E%E8%83%8C%E8%AF%B5%E5%86%85%E5%AE%B9day5/" data-id="cknublgci0023v8uh4z307jvu" data-title="函数基础" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/python%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/" rel="tag">python基础知识</a></li></ul>

    </footer>
  </div>
  
</article>



  
    <article id="post-bootstrap使用教程" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/04/12/bootstrap%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B/" class="article-date">
  <time class="dt-published" datetime="2021-04-12T14:00:10.634Z" itemprop="datePublished">2021-04-12</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/04/12/bootstrap%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B/">vue安装bootstrap组件</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h3 id="bootstrap使用教程"><a href="#bootstrap使用教程" class="headerlink" title="bootstrap使用教程"></a>bootstrap使用教程</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 首先进行安装</span></span><br><span class="line">cnpm install bootstrap --save-dev</span><br><span class="line">cnpm install jquery --save-dev</span><br><span class="line">cnpm install popper.js --save-dev</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 在main.js中:</span></span><br><span class="line">import &#x27;bootstrap&#x27;</span><br><span class="line">import $ from &#x27;jquery&#x27;</span><br><span class="line">import &#x27;bootstrap/dist/css/bootstrap.min.css&#x27;</span><br><span class="line">import &#x27;bootstrap/dist/js/bootstrap.min.js&#x27;</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 在index.html中的&lt;body&gt;&lt;/body&gt;中导入</span></span><br><span class="line">&lt;!-- 新 Bootstrap 核心 CSS 文件 --&gt; &lt;link href=&quot;https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;&gt; &lt;!-- jQuery文件。务必在bootstrap.min.js 之前引入 --&gt;</span><br><span class="line">    &lt;script src=&quot;https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js&quot;&gt;&lt;/script&gt; &lt;!-- 最新的 Bootstrap 核心 JavaScript 文件 --&gt;</span><br><span class="line">    &lt;script src=&quot;https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js&quot;&gt;&lt;/script&gt;</span><br></pre></td></tr></table></figure>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/04/12/bootstrap%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B/" data-id="cknublgbi000dv8uh4dowc78e" data-title="vue安装bootstrap组件" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/vue/" rel="tag">vue</a></li></ul>

    </footer>
  </div>
  
</article>



  
    <article id="post-vue安装element-ui组件" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/04/12/vue%E5%AE%89%E8%A3%85element-ui%E7%BB%84%E4%BB%B6/" class="article-date">
  <time class="dt-published" datetime="2021-04-12T13:53:16.610Z" itemprop="datePublished">2021-04-12</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/04/12/vue%E5%AE%89%E8%A3%85element-ui%E7%BB%84%E4%BB%B6/">vue安装element-ui组件</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h2 id="安装element-ui组件使用"><a href="#安装element-ui组件使用" class="headerlink" title="安装element-ui组件使用"></a>安装element-ui组件使用</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cnpm install element-ui --save</span><br></pre></td></tr></table></figure>
<h2 id="将以下代码导入main-js主文件中"><a href="#将以下代码导入main-js主文件中" class="headerlink" title="将以下代码导入main.js主文件中"></a>将以下代码导入main.js主文件中</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">  <span class="comment">// 导入element-ui组件</span></span><br><span class="line"><span class="keyword">import</span> ElementUI <span class="keyword">from</span> <span class="string">&#x27;element-ui&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">&#x27;element-ui/lib/theme-chalk/index.css&#x27;</span>;</span><br><span class="line">Vue.use(ElementUI);</span><br></pre></td></tr></table></figure>
<p>之后就可以使用element-ui组件了</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/04/12/vue%E5%AE%89%E8%A3%85element-ui%E7%BB%84%E4%BB%B6/" data-id="cknublgc6001fv8uh2gzgce3q" data-title="vue安装element-ui组件" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/vue/" rel="tag">vue</a></li></ul>

    </footer>
  </div>
  
</article>



  
    <article id="post-Django中choices设置的操作" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog1/2021/04/12/Django%E4%B8%ADchoices%E8%AE%BE%E7%BD%AE%E7%9A%84%E6%93%8D%E4%BD%9C/" class="article-date">
  <time class="dt-published" datetime="2021-04-12T11:41:22.353Z" itemprop="datePublished">2021-04-12</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog1/2021/04/12/Django%E4%B8%ADchoices%E8%AE%BE%E7%BD%AE%E7%9A%84%E6%93%8D%E4%BD%9C/">django中choices设置的操作</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h2 id="Django中choices设置的操作"><a href="#Django中choices设置的操作" class="headerlink" title="Django中choices设置的操作"></a>Django中choices设置的操作</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># python模型中</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">AuditWorkFlow</span>(<span class="params">models.Model</span>):</span></span><br><span class="line">    workflow = models.ForeignKey(WorkFlow, on_delete=models.CASCADE)</span><br><span class="line">    sequence = models.SmallIntegerField(verbose_name=<span class="string">&#x27;序号&#x27;</span>)</span><br><span class="line">    audit_type = models.CharField(choices=((<span class="string">&quot;1&quot;</span>, <span class="string">&#x27;审核角色&#x27;</span>), (<span class="string">&quot;2&quot;</span>, <span class="string">&#x27;审核用户&#x27;</span>)), max_length=<span class="number">20</span>)</span><br><span class="line">    audit_id = models.IntegerField(verbose_name=<span class="string">&#x27;审核用户或角色ID&#x27;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Meta</span>:</span></span><br><span class="line">        db_table = <span class="string">&#x27;auditworkflow&#x27;</span></span><br><span class="line">        verbose_name = <span class="string">&#x27;审核请假工单表&#x27;</span></span><br><span class="line">        verbose_name_plural = verbose_name</span><br></pre></td></tr></table></figure>
<p>audit_type字段 使用了choices属性，枚举了可能的选择，期中 “1”,”2”是模型的实际值，存储到数据库中；“审核角色”，“审核用户”是可读名。</p>
<ul>
<li>如何获取字段的可读名</li>
</ul>
<p>使用get_FOO_display()方法，FOO是字段的名称。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># python序列化器中</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">AuditWorkFlowListSer</span>(<span class="params">ModelSerializer</span>):</span></span><br><span class="line">    <span class="comment"># 通过外键找到主表名字</span></span><br><span class="line">    workflow = serializers.CharField(source=<span class="string">&quot;workflow.name&quot;</span>)</span><br><span class="line">    </span><br><span class="line">    <span class="comment"># 含有choices的字段名</span></span><br><span class="line">    audit_type = SerializerMethodField()</span><br><span class="line"></span><br><span class="line">    audit_id = SerializerMethodField()</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 使用get_字段_display()来获取choices可读字段</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">get_audit_type</span>(<span class="params">self,obj</span>):</span></span><br><span class="line">        <span class="keyword">return</span> obj.get_audit_type_display()</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">get_audit_id</span>(<span class="params">self,obj</span>):</span></span><br><span class="line">        <span class="keyword">if</span> obj.audit_type == <span class="string">&quot;1&quot;</span>:</span><br><span class="line">            <span class="keyword">return</span> User.objects.<span class="built_in">filter</span>(<span class="built_in">id</span>=obj.audit_id).first().username</span><br><span class="line">        <span class="keyword">elif</span> obj.audit_type == <span class="string">&quot;2&quot;</span>:</span><br><span class="line">            <span class="keyword">return</span> Role.objects.<span class="built_in">filter</span>(<span class="built_in">id</span>=obj.audit_id).first().c_name</span><br><span class="line"></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Meta</span>:</span></span><br><span class="line">        model = AuditWorkFlow</span><br><span class="line">        fields = <span class="string">&#x27;__all__&#x27;</span></span><br></pre></td></tr></table></figure>
<p>obj就是一个AuditWorkFlow实例，audit_type就是有choices的字段名</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># python视图view</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">AuditWorkFlowView</span>(<span class="params">ModelViewSet</span>):</span></span><br><span class="line">    queryset = AuditWorkFlow.objects.<span class="built_in">all</span>()</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">get_queryset</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="keyword">if</span> self.action == <span class="string">&quot;list&quot;</span>:</span><br><span class="line">            workflow_id = self.request.GET.get(<span class="string">&#x27;flow_id&#x27;</span>)</span><br><span class="line">            print(workflow_id)</span><br><span class="line">            <span class="keyword">if</span> workflow_id:</span><br><span class="line">                audit_set = AuditWorkFlow.objects.<span class="built_in">filter</span>(workflow_id=workflow_id)</span><br><span class="line">                <span class="keyword">return</span> audit_set</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                audit_set = AuditWorkFlow.objects.<span class="built_in">all</span>()</span><br><span class="line">                <span class="keyword">return</span> audit_set</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            audit_set = AuditWorkFlow.objects.<span class="built_in">all</span>()</span><br><span class="line">            <span class="keyword">return</span> audit_set</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">get_serializer_class</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="comment"># 如果使用GET方法查询全部，则使用AuditWorkFlowListSer序列化器</span></span><br><span class="line">        <span class="keyword">if</span> self.action == <span class="string">&quot;list&quot;</span>:</span><br><span class="line">            <span class="keyword">return</span> AuditWorkFlowListSer</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            <span class="keyword">return</span> AuditWorkFlowSer</span><br></pre></td></tr></table></figure>
<p><img src="https://i.loli.net/2021/04/12/CjbxagLzUpEkQyd.png" alt="以上为完成后的结果图"></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://shangguan-lingfeng.gitee.io/blog1/2021/04/12/Django%E4%B8%ADchoices%E8%AE%BE%E7%BD%AE%E7%9A%84%E6%93%8D%E4%BD%9C/" data-id="cknublgbd0004v8uh3edgaorr" data-title="django中choices设置的操作" class="article-share-link">Teilen</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog1/tags/django/" rel="tag">django</a></li></ul>

    </footer>
  </div>
  
</article>



  


  <nav id="page-nav">
    
    <a class="extend prev" rel="prev" href="/blog1/">&laquo; zurück</a><a class="page-number" href="/blog1/">1</a><span class="page-number current">2</span><a class="page-number" href="/blog1/page/3/">3</a><a class="page-number" href="/blog1/page/4/">4</a><a class="extend next" rel="next" href="/blog1/page/3/">weiter &raquo;</a>
  </nav>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/CentOS/" rel="tag">CentOS</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/Flask/" rel="tag">Flask</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/django/" rel="tag">django</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/docker/" rel="tag">docker</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/gitee/" rel="tag">gitee</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/linux/" rel="tag">linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/mysql/" rel="tag">mysql</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/python/" rel="tag">python</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/python%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/" rel="tag">python基础知识</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/redis/" rel="tag">redis</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/vue/" rel="tag">vue</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/webshell/" rel="tag">webshell</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/%E4%BA%91%E4%B8%BB%E6%9C%BA%E5%AE%9E%E7%8E%B0%E8%A7%86%E9%A2%91%E7%9B%B4%E6%92%AD/" rel="tag">云主机实现视频直播</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog1/tags/%E5%85%B3%E4%BA%8E%E7%AC%AC%E4%B8%89%E6%96%B9/" rel="tag">关于第三方</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/blog1/tags/CentOS/" style="font-size: 17.5px;">CentOS</a> <a href="/blog1/tags/Flask/" style="font-size: 10px;">Flask</a> <a href="/blog1/tags/django/" style="font-size: 12.5px;">django</a> <a href="/blog1/tags/docker/" style="font-size: 12.5px;">docker</a> <a href="/blog1/tags/gitee/" style="font-size: 10px;">gitee</a> <a href="/blog1/tags/linux/" style="font-size: 10px;">linux</a> <a href="/blog1/tags/mysql/" style="font-size: 12.5px;">mysql</a> <a href="/blog1/tags/python/" style="font-size: 15px;">python</a> <a href="/blog1/tags/python%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/" style="font-size: 17.5px;">python基础知识</a> <a href="/blog1/tags/redis/" style="font-size: 12.5px;">redis</a> <a href="/blog1/tags/vue/" style="font-size: 20px;">vue</a> <a href="/blog1/tags/webshell/" style="font-size: 10px;">webshell</a> <a href="/blog1/tags/%E4%BA%91%E4%B8%BB%E6%9C%BA%E5%AE%9E%E7%8E%B0%E8%A7%86%E9%A2%91%E7%9B%B4%E6%92%AD/" style="font-size: 10px;">云主机实现视频直播</a> <a href="/blog1/tags/%E5%85%B3%E4%BA%8E%E7%AC%AC%E4%B8%89%E6%96%B9/" style="font-size: 12.5px;">关于第三方</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archiv</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog1/archives/2021/05/">五月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog1/archives/2021/04/">四月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog1/archives/2021/03/">三月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog1/archives/2021/02/">二月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/blog1/archives/2021/01/">一月 2021</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">letzter Beitrag</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/blog1/2021/05/14/docker+CentOS+mysql%E5%AE%9E%E7%8E%B0%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5/">docker+CentOS+mysql实现主从同步</a>
          </li>
        
          <li>
            <a href="/blog1/2021/05/13/mysql%E5%AE%9E%E7%8E%B0%E8%AF%BB%E5%86%99%E5%88%86%E7%A6%BB(%E5%9C%A8%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5%E5%9F%BA%E7%A1%80%E4%B8%8A)/">mysql实现读写分离</a>
          </li>
        
          <li>
            <a href="/blog1/2021/05/12/%E5%9C%A8%E9%A1%B9%E7%9B%AE%E4%B8%AD%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3/">在项目中自动生成接口文档</a>
          </li>
        
          <li>
            <a href="/blog1/2021/05/12/mysql%E5%AE%9E%E7%8E%B0%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5/">mysql实现主从同步</a>
          </li>
        
          <li>
            <a href="/blog1/2021/05/09/CentOS%E9%83%A8%E7%BD%B2flask%E9%A1%B9%E7%9B%AE/">nginx部署flask项目</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2021 Jerry<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/blog1/" class="mobile-nav-link">Home</a>
  
    <a href="/blog1/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/blog1/js/jquery-3.4.1.min.js"></script>



  
<script src="/blog1/fancybox/jquery.fancybox.min.js"></script>




<script src="/blog1/js/script.js"></script>





  </div>
</body>
</html>